#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[1000005];
bool cmp(int a, int b) {
	return a>b;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; ++i) scanf("%d", &a[i]);
	int p=0;
	for (int i=1; i<n; ++i) {
		if (a[i]>a[p]) p=i; 
	}
	sort(a+p, a+n, cmp);
	if (p==0) for (int i=p; i<n; ++i) printf("%d%c", a[i], (i==n-1?'\n':' '));
	else for (int i=p; i<n; ++i) printf("%d ", a[i]);
	for (int i=p-1; i>=0; --i) printf("%d%c", a[i], (i==0?'\n':' '));
	return 0;
}
